package com.zjht.gmcc.servlet.sys;
/**
 * 朱家进
 * 2010-08-01
 * 
 * 适用于检查mobileorgacode是否存在
 */

import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;


public class MobileorgacodeCheck extends BaseServlet {


	/**
	 * 格式
	 * <state>
	 *   <value>1</value>         //当前渠道标识已存在
	 *   <value>****厅</value>    //营业厅名称
	 * </state>  
	 */
	private static final long serialVersionUID = 7145765698818888020L;

	public boolean process(HttpServletRequest request, HttpServletResponse response,HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)throws Exception {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");

		StringBuilder sb = new StringBuilder("<state>");

		PreparedStatement ps = null;
		ResultSet rs = null;
		String shortName = null;
		String mobileorgacode = request.getParameter("mobileorgacode").trim();	
		String sql = null;
		String orgacode = null;

		sql = "SELECT orgacode FROM mobileorgatolocal where mobileorgacode=?";
		ps = myJDBC.prepareStatement(sql);
		ps.setString(1, mobileorgacode.toUpperCase().trim());
		rs = ps.executeQuery();
		if (rs.next()){
			sb.append("<value>1</value>");
			orgacode = rs.getString("orgacode");
		}
		else
			sb.append("<value>0</value>");
		rs.close();
				
		sql = "SELECT shortname FROM organiza where orgacode=?";
		ps = myJDBC.prepareStatement(sql);
		ps.setString(1, orgacode);
		rs = ps.executeQuery();
		if (rs.next()){
			shortName = rs.getString("shortName");				
			sb.append("<value>"+shortName+"["+orgacode+"]</value>");		
		}			
		else
			sb.append("<value>0</value>");
		rs.close();
		ps.close();
		ps = null;
		sb.append("</state>");

		out.write(sb.toString());
		return true;

	}
}
